home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / Smooth Wave With Blanks < prev    next >
Text File  |  1995-12-31  |  3KB  |  80 lines

  1. #pragma rtGlobals=1
  2.  
  3. | See the “Sectional Smoothing” example experiment for an example
  4.  
  5. Function FindSegStart(source, segStart, theEnd)    | returns # of first "normal" data point in segment
  6.     Wave source                                        | wave being searched
  7.     Variable segStart                                    | point to start search from
  8.     Variable theEnd                                    | last point to search
  9.                                                         | NOTE: if no more normal points in wave, returns neg #
  10.     Variable curPoint = segStart
  11.     
  12.     if (curPoint >= theEnd)
  13.         return (-1)
  14.     endif
  15.     
  16.     do
  17.         if (numtype(source[curPoint]) == 0)        | is this a normal number
  18.             return (curPoint)                        | we've found segment start
  19.         endif
  20.         curPoint += 1
  21.     while (curPoint < theEnd)
  22.     return (-2)                                        | if here, there are no normal points in segment
  23. End
  24.  
  25. Function FindSegEnd(source, segStart, theEnd)    | returns # of last "normal" data point in segment
  26.     Wave source                                    | wave being searched
  27.     Variable segStart                                | point to start search from
  28.     Variable theEnd                                | last point to search
  29.     
  30.     Variable curPoint = segStart+1
  31.                                                     | NOTE: assumes source[segStart] is normal
  32.     if (curPoint > theEnd)
  33.         return (theEnd)
  34.     endif
  35.     
  36.     do
  37.         if (numtype(source[curPoint]))        | is this an abnormal number
  38.             return (curPoint-1)                    | we've found segment end
  39.         endif
  40.         curPoint += 1
  41.     while (curPoint <= theEnd)
  42.     return (theEnd)
  43. End
  44.  
  45. Proc SmoothWaveWithBlanks(source, dest, passes)
  46.     String source                                | name of wave to supply data to be smoothed
  47.     Prompt source, "Source Wave"
  48.     String dest                                    | name of wave to put result in (can be same as source)
  49.     Prompt dest, "Dest Wave"                | NOTE: dest assumed to have same number of points as source
  50.     Variable passes = 5                        | number of desired smoothing passes
  51.     Prompt passes, "Number of passes: "
  52.     
  53.     Silent 1
  54.  
  55.     Variable lastPoint = numpnts($source)-1
  56.     Variable segStart, segEnd                    | point numbers for segment being worked on
  57.     Variable segments=0                        | for debugging
  58.  
  59.     segStart = 0;segEnd = 0
  60.     do
  61.         segStart = FindSegStart($source, segStart, lastPoint)    | find start of next segment
  62.         Print "segStart = " + num2istr(segStart)
  63.         if (segStart < 0)
  64.             break                                                    | no more normal points
  65.         endif
  66.         segEnd = FindSegEnd($source, segStart, lastPoint)        | find end of next segment
  67.         Print "segEnd = " + num2istr(segEnd)
  68.         if (segEnd > segStart)                                        | don't smooth one point        
  69.             Duplicate /O/R=[segStart,segEnd] $source, root:tempSegWave
  70.             Smooth passes, root:tempSegWave
  71.             $dest[segStart, segEnd] = root:tempSegWave[p-segStart]
  72.             segments += 1
  73.         endif
  74.         
  75.         segStart = segEnd+1
  76.     while (segStart < lastPoint)
  77.     Print  "Smoothed " + num2istr(segments) + " segments"
  78.     KillWaves root:tempSegWave
  79. EndMacro
  80.